<?php 

class RecipeMainsController extends AppController{
	
	//public $scaffold;

	public $name = 'RecipeMains';
	public $layout = 'admin';

	public function beforeFilter()
	{
		parent::beforeFilter();
	}

	public function admin_index()
	{
		$this->set(array('title_for_layout' => 'All recipes mains'));
		$this->RecipeMain->recursive = -1;
		$this->paginate = array('order' => array('title' => 'ASC'));
		$this->set('recipemain',$this->paginate());
	}

	public function admin_add()
	{
		$this->set(array('title_for_layout' => 'Add new recipe main'));

		if($this->request->is('post') || $this->request->is('put'))
		{
			$this->RecipeMain->create();

			if($this->RecipeMain->save($this->request->data))
			{
				$this->Session->setFlash('The recipe main has been saved');
				$this->redirect(array('controller' => 'recipemains', 'action' => 'index'));

			}
			else
			{
				$this->Session->setFlash('The recipe main has not been saved, please try again');
			}
		}

	}

	public function admin_edit($id = null)
	{
		$this->set(array('title_for_layout' => 'Edit the recipe main'));

		if(!$id)
		{
			$this->Session->setFlash('Please provide a recipe main id');
			$this->redirect(array('controller' => 'recipemains', 'action' => 'index'));
		}

		$recipemain = $this->RecipeMain->findById($id);

		if(!$recipemain)
		{
			$this->Session->setFlash('Please provide a valid recipe main id');
			$this->redirect(array('controller' => 'recipemains', 'action' => 'index'));
		}

		$this->RecipeCategory->id = $id;

		if($this->request->is('post') || $this->request->is('put'))
		{
			

			if($this->RecipeCategory->save($this->request->data))
			{
				$this->Session->setFlash('The recipe category has been updated');
				$this->redirect(array('controller' => 'recipecategories', 'action' => 'index'));
			}
			else
			{
				$this->Session->setFlash('The recipe category has not been saved, please try again');
			}
		}
	
		$this->RecipeCategory->recursive = -1;
		$this->request->data = $this->RecipeCategory->read();

		$listcategory = $this->RecipeCategory->find('all', array('recursive' => -1, 'fields' => array('id', 'title'), 'order' => array('title' => 'ASC'),));
		$this->set('listcategory', $listcategory);	

	}

	public function admin_delete()
	{


	}
	
}

?>